<?php
/**
 * Core_Role_Record
 * 
 * @author naspeh
 * @version $Id: Record.php 659 2008-06-15 11:34:26Z naspeh $
 */
class Core_Role_Record extends Core_Record 
{
    /**
     * Инициализация
     *
     */
    public function init()
    {
        // init tie acl resource
        $this->setAclResourceRowClass('Core_Acl_Resource_Role');
        $this->setKeyRow('name', 'role');
                
        // init source
        $this->setSource(new Core_Table_Roles());
        
        //init fields
        $this->addField('id', array('title'=>'ID', 'order'=>true));
        $this->addField('name', array('title'=>'Имя', 'order'=>true));
        $this->addField('email', array('title'=>'Email', 'order'=>true));
        $this->addField('fullname', array('title'=>'Полное имя', 'order'=>true));
        $this->addField('is_login', array('title'=>'Вход', 'type' => 'boolean', 'order'=>true));
        
        //init actions
        $this->addAction('remove', 'remove', array(
            'type'     => 'submit',
            'label'    => 'Удалить',
            'attribs'  => array(
                'class' => 'negative',
                'icon'  => 'cross'
            ),     
        ));
        
        //init actions for row
        $this->addActionForRow('edit', 'role/edit')
             ->addActionForRow('access', 'role/access');
    }
    /**
     * Удаление роли
     *
     * @return unknown
     */
    public function removeAction()
    {
        $ids = $this->getExtractIds('remove');
        if (!empty($ids)) {
            $tableRoles = new Core_Table_Roles();
            $result = $tableRoles->delete(array('id in (?)' => array($ids)));
            return $result;
        }
        return 0;
    }
}